﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCWeb.Models;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace MVCWeb.Controllers
{
    public class TvController : Controller
    {


        //
        // GET: /Tv/
        public ActionResult Index()
        {
            return View("TvIndex");
        }

        [HttpGet]
        public ActionResult Search(int display, int make, int size, int res, int refresh, int shipping)
        {
            //var displays = new[] { "LED", "LCD", "Plasma" }.Select(d => new SelectListItem { Value = d, Text = d });
           
            //List<TvModel> DisplayList = TvClientService.GetDisplayList();//new SelectList(displays, "Value", "Text")
           
            
            List<TvModel> model = TvClientService.SearchItem(display, make, size);

            return View("TvResults");
        }

        public ActionResult ViewDisplays()
        {
            ViewData["MyDisplay"] = new SelectList(new[] { "LCD", "LED", "Plasma"}, "LCD");
            ViewData["MyMake"] = new SelectList(new[] {"Samsung", "Sony", "Sharp", "LG", "Coby", "Panasonic"}, "Samsung");
            ViewData["MySize"] = new SelectList(new[] {32, 40, 55}, 32);
            return View("ViewDisplays");
        }

        public ActionResult WebViewDisplays()
        {
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            ViewData["MyDisplay"] = new SelectList(new[] { "LCD", "LED", "Plasma" }, "LCD");
            ViewData["MyMake"] = new SelectList(new[] { "Samsung", "Sony", "Sharp", "LG", "Coby", "Panasonic" }, "Samsung");
            ViewData["MySize"] = new SelectList(new[] { 32, 40, 55 }, 32);
            return View("WebViewDisplays");
        }

        [HttpPost]
        public ActionResult ViewDisplays(FormCollection form)
        {
            try
            {
                string display = form["MyDisplay"];
                string make = form["MyMake"];
                string size = form["MySize"];
                int displayindex = 0;int makeindex = 0;int sizeindex = 0;
               // int resindex = 0;int refreshindex = 0;int shipindex = 0;

                //find display index
                if (display.Equals("LCD"))
                    displayindex = 1;
                else if (display.Equals("LED"))
                    displayindex = 2;
                else if (display.Equals("Plasma"))
                    displayindex = 3;

                //find make index
                if (make.Equals("Samsung"))
                    makeindex = 1;
                else if (make.Equals("Sony"))
                    makeindex = 2;
                else if (make.Equals("Sharp"))
                    makeindex = 3;
                else if (make.Equals("LG"))
                    makeindex = 4;
                else if (make.Equals("Coby"))
                    makeindex = 5;
                else if (make.Equals("Panasonic"))
                    makeindex = 6;

                //find size index
                if (size.Equals("32"))
                    sizeindex = 1;
                else if (size.Equals("40"))
                    sizeindex = 2;
                else if (size.Equals("55"))
                    sizeindex = 3;

                List<TvModel> tv = new List<TvModel>();
                tv = TvClientService.SearchItem(displayindex, makeindex, sizeindex);
                
                return View("ViewResults", tv);
            }
            catch
            {
                return View();
            }

        }


        [HttpPost]
        public ActionResult WebViewDisplays(FormCollection form)
        {
            try
            {
                string display = form["MyDisplay"];
                string make = form["MyMake"];
                string size = form["MySize"];
                int displayindex = 0; int makeindex = 0; int sizeindex = 0;
                // int resindex = 0;int refreshindex = 0;int shipindex = 0;

                //find display index
                if (display.Equals("LCD"))
                    displayindex = 1;
                else if (display.Equals("LED"))
                    displayindex = 2;
                else if (display.Equals("Plasma"))
                    displayindex = 3;

                //find make index
                if (make.Equals("Samsung"))
                    makeindex = 1;
                else if (make.Equals("Sony"))
                    makeindex = 2;
                else if (make.Equals("Sharp"))
                    makeindex = 3;
                else if (make.Equals("LG"))
                    makeindex = 4;
                else if (make.Equals("Coby"))
                    makeindex = 5;
                else if (make.Equals("Panasonic"))
                    makeindex = 6;

                //find size index
                if (size.Equals("32"))
                    sizeindex = 1;
                else if (size.Equals("40"))
                    sizeindex = 2;
                else if (size.Equals("55"))
                    sizeindex = 3;

                List<TvModel> tv = new List<TvModel>();
                tv = TvClientService.SearchItem(displayindex, makeindex, sizeindex);

                return View("WebViewResults", tv);
            }
            catch
            {
                return View();
            }

        }

        public ActionResult OutOfStockDetail() 
        {
            List<TvModelPrtial> plist = TvClientService.OutOfStockDetail();

            return View("OutOfStockDetail",plist);
        
        }

        public ActionResult GetTopFive() 
        {
            List<TvModelPrtial> plist = TvClientService.GetTopFive();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            ViewData["webmasterPartial"] += "Popular Item List " + "<a href='" + url.Action("GetTopFive", "Tv") + "'>Check Popular Items </a>" + "<br />";

            return View("GetTopFive", plist);
        
        }

        public ActionResult OutOfStock() 
        {
            int num = TvClientService.GetNumberOfOutOfStock();
            UrlHelper url = new UrlHelper(HttpContext.Request.RequestContext);
            ViewData["webmasterPartial"] += "Total Out of Stock TV: " + num + " " + "<a href='" + url.Action("OutOfStockDetail", "Tv") + "'>Sold Out Items List</a>" + "<br />";

            return View(num);
        }



    }
}
